package com.yan.domain;

import com.yan.anno.MyJsonFormat;
import com.yan.anno.MyJsonIgnore;
import com.yan.anno.MyJsonProperty;

import java.util.Date;

/**
 * @author taoge
 * @Date 2024/8/15 11:51
 * @Description
 */
public class Book {
    @MyJsonProperty(value = "newName")
    private String name;
    @MyJsonIgnore
    private String author;
    private Double price;
    @MyJsonFormat(pattern = "yyyy-MM-dd")
    private Date createDate;

    public Book(String name, String author, Double price, Date createDate) {
        this.name = name;
        this.author = author;
        this.price = price;
        this.createDate = createDate;
    }

    public Book() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Book book = (Book) o;

        if (name != null ? !name.equals(book.name) : book.name != null) return false;
        if (author != null ? !author.equals(book.author) : book.author != null) return false;
        if (price != null ? !price.equals(book.price) : book.price != null) return false;
        return createDate != null ? createDate.equals(book.createDate) : book.createDate == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (author != null ? author.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (createDate != null ? createDate.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                ", createDate=" + createDate +
                '}';
    }
}
